from django.conf import settings
from itsdangerous import TimedJSONWebSignatureSerializer as Serializer
#加密及解密
class SecretOauth(object):
    def dumps(self, datas): #加密
        serializer = Serializer(secret_key=settings.SECRET_KEY, expires_in=24*15*60)
        result = serializer.dumps(datas) #加密
        return result
    def loads(self, secret_datas): #解密
        serializer = Serializer(secret_key=settings.SECRET_KEY, expires_in=24*15*60)
        result = serializer.loads(secret_datas)
        return result
#拼接验证邮箱的路由
def generate_verify_email_url(email):
    data_dict = {'email':email}
    secret_datas = SecretOauth().dumps(data_dict).decode()
    active_url = settings.EMAIL_VERIFY_URL + '?token=' + secret_datas
    return active_url